﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Remoting.Messaging;

namespace lwzlz.Common
{
    public class DatabaseHelper
    {

        public static SqlConnection GetSqlConnection(string connName)
        {
            var conn = CallContext.GetData(connName) as SqlConnection;
            if (conn == null)
            {
                var config = ConfigurationManager.ConnectionStrings[connName];
                conn = new SqlConnection(config.ConnectionString);
                CallContext.SetData(connName, conn);
            }
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            return conn;
        }
    }
}
